# Default Dockerfile
#
# @link     https://www.hyperf.io
# @document https://hyperf.wiki
# @contact  group@hyperf.io
# @license  https://github.com/hyperf/hyperf/blob/master/LICENSE

FROM hyperf/hyperf:8.2-alpine-v3.19-swoole
LABEL maintainer="Hyperf Developers <group@hyperf.io>" version="1.0" license="MIT" app.name="Hyperf"

##
# ---------- env settings ----------
##
# --build-arg timezone=Asia/Shanghai
ARG timezone

ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \
    COMPOSER_VERSION=2.7.7 \
    APP_ENV=prod

# update
RUN set -ex \
    && apk update \
    #install mongodb.so,由于是apline版本,所以需要先安装以下包 \
    && apk add autoconf gcc g++ make libffi-dev openssl-dev php-pear pcre2-dev zlib-dev php82-dev protobuf ffmpeg \
    && pecl channel-update pecl.php.net \
    # install mongodb.so
    && pecl install mongodb \
    && touch /etc/php82/conf.d/mongodb.ini \
    && echo "extension=mongodb.so" > /etc/php82/conf.d/mongodb.ini \
    # install memcached.so \
    && apk add libmemcached-dev \
    && pecl install memcached \
    && touch /etc/php82/conf.d/memcached.ini \
    && echo "extension=memcached.so" > /etc/php82/conf.d/memcached.ini \
    # install xdebug.so
#    && pecl install xdebug \
#    && touch /etc/php82/conf.d/xdebug.ini \
#    && echo "zend_extension=xdebug.so" > /etc/php82/conf.d/xdebug.ini \
#    && echo "xdebug.idekey='PHPSTORM_LAGO'" >> /etc/php82/conf.d/xdebug.ini \
#    && echo "xdebug.mode=debug" >> /etc/php82/conf.d/xdebug.ini \
#    && echo "xdebug.discover_client_host=true" >> /etc/php82/conf.d/xdebug.ini \
#    && echo "xdebug.client_port=9001" >> /etc/php82/conf.d/xdebug.ini \
#    && echo "xdebug.client_host='192.168.31.8'" >> /etc/php82/conf.d/xdebug.ini \
#    && echo "xdebug.start_with_request=1" >> /etc/php82/conf.d/xdebug.ini \
#    && echo "xdebug.remote_handler = 'dbgp'" >> /etc/php82/conf.d/xdebug.ini \
    # install composer
    && wget -nv -O /usr/local/bin/composer https://github.com/composer/composer/releases/download/${COMPOSER_VERSION}/composer.phar \
    && chmod u+x /usr/local/bin/composer \
    && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer \
    # show php version and extensions
    && php -v \
    && php -m \
    && php --ri swoole \
    #  ---------- some config ----------
    && cd /etc/php* \
    # - config PHP
    && { \
        echo "upload_max_filesize=128M"; \
        echo "post_max_size=128M"; \
        echo "memory_limit=2G"; \
        echo "date.timezone=${TIMEZONE}"; \
    } | tee conf.d/99_overrides.ini \
    # - config timezone
    && ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
    && echo "${TIMEZONE}" > /etc/timezone \
    # ---------- clear works ----------
    && rm -rf /var/cache/apk/* /tmp/* /usr/share/man \
    && echo -e "\033[42;37m Build Completed :).\033[0m\n"

WORKDIR /code

